﻿@using PagedList.Mvc
@model PagedList.IPagedList<CubicFWNet.Data.ViewModal.NewsView>
@{
    ViewBag.Title = "Index";
    //var modules = ViewBag.Modules as IEnumerable<CubicFWNet.Data.Models.NewsType>;
}

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        查询学习资料
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("LearnIndex", "Learning")">查询学习资料</a></li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="box box-solid">
                <div class="box-nav clearfix">
                    <div class="col-sm-12 col-md-3">
                        @*<a class="btn btn-primary" href="javascript:void(0)" onclick="query();" title="查询"><i class="fa fa-plus-square"></i>&nbsp;查询</a>*@
                        @*<button type="button" class="btn btn-warning" oncancel="edit();" title="修改"><i class="fa fa-edit"></i></button>
                            <button type="button" class="btn btn-danger" onclick="del()" title="删除"><i class="fa fa-trash-o"></i></button>*@
                        @*<button type="button" class="btn btn-info" title="查看"><i class="fa fa-search-plus"></i></button>*@
                        <a class="btn btn-default" onclick="$.reload()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table class="footable table table-stripped table-bordered table-hover" id="footable" data-page-size="20" data-filter=#filter>
                        <thead>
                            <tr>
                                <th data-sort-ignore="true">
                                    资料名称
                                </th>
                                <th data-sort-ignore="true">
                                    类型
                                </th>
                                <th data-sort-ignore="true" data-hide="phone,tablet">
                                    创建时间
                                </th>
                                @*<th>
                                        浏览记录
                                    </th>*@
                                <th data-sort-ignore="true">
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (null != Model)
                            {
                                foreach (var item in Model)
                                {
                                    <tr>
                                        <td>
                                            @item.Name
                                        </td>
                                        <td>
                                            @item.TypeName
                                        </td>
                                        <td>
                                            @item.CreateTime
                                        </td>
                                        @*<td>
                                                查看
                                            </td>*@
                                        <td>
                                            <a class="btn bg-blue btn-xs" href="@Url.Action("Edit", "Learning", new { PID = item.Id })">编辑</a>
                                            <a class="btn bg-orange btn-xs" id="del" name="del" href="javascript:void(0)" onclick="del(this,'@item.Id');">删除</a>
                                            @* <button type="button" onclick="edit('@item.Id');" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i></button>*@
                                            @*<button type="button" class="btn  btn-xs btn-info btn-flat"><i class="fa fa-search"></i></button>*@
                                            @*<button type="button" onclick="del(this,'@item.Id');" class="btn  btn-xs btn-danger"><i class="fa fa-trash-o"></i></button>*@
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="7">
                                    每页 @Model.PageSize 条记录，共 @Model.PageCount 页，当前第 @Model.PageNumber 页
                                    @Html.PagedListPager(Model, page => Url.Action("LearnIndex", new { page }))
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<div class="modal" id="queryDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">查询</h4>
            </div>
            <form class="form-horizontal" id="frmquery" action="@Url.Action("LearnIndex", "Learning")" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 关键字 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="productName" name="productName" value="" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 开始时间 </label>
                        <div class="col-sm-8">
                            <input id="starttime" name="starttime" type="date" class="form-control " />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 结束时间 </label>
                        <div class="col-sm-8">
                            <input id="endtime" name="endtime" type="date" class="form-control " />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
</div>


<div class="modal" id="editDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">修改学习资料</h4>
            </div>
            <form class="form-horizontal" id="frmedit" action="@Url.Action("Edit", "Learning")" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 名称 </label>
                        <div class="col-sm-9">
                            <input type="hidden" class="form-control formId" id="Id" name="Id" />
                            <input type="text" class="form-control" id="Name" name="Name" required />
                            <input type="hidden" class="form-control formId" id="Type" name="Type" />
                        </div>
                    </div>
                    @*<div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for=""> 类型 </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="TypeName" name="TypeName" value="0" />
                            </div>
                        </div>*@
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 标题 </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Introduct" name="Introduct" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 发布人 </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Publisher" name="Publisher" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 排序 </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Sort" name="Sort" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">是否启用</label>
                        <div class="col-sm-9">
                            <input type="checkbox" id="Status" name="Status" checked />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">是否设置权限</label>
                        <div class="col-sm-9">
                            <input type="checkbox" id="IsLimit" name="IsLimit" checked />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">内容</label>
                        <div class="col-sm-9">

                            <textarea id="NewsContent" name="NewsContent" rows="10" cols="80" style="visibility: hidden; display: none;">
                                <span id="NewsContent1"></span>
                            </textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@*@section Styles {
        @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    }*@

@section Scripts {
    <script src="~/Scripts/ckeditor/ckeditor.js"></script>
    <script type="text/javascript">
        $(function () {
            CKEDITOR.replace('NewsContent');
        });

        $(document).ready(function () {
            $('#footable').footable();
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            $.reload();
                        }
                    });
                }
            });
            
        });

        function create() {
            $("#frmedit").formInit();
            $('#editDlg').modal();
        }

        //$(function () {
        //    $("#edit").click(function () {
        //        if (!!id) {
        //            $.ajax({
        //                url: "/Learning/GetFormJson",
        //                data: { id: id },
        //                dataType: "json",
        //                async: false,
        //                success: function (data) {
        //                    $("#frmedit").formSerialize(data);
        //                    $("#editDlg").modal();
        //                }
        //            });
        //        }
        //    })
        //})
        function edit(id) {
            if (!!id) {
                $.ajax({
                    //url: "/Learning/GetFormJson",
                    url: '@Url.Action("GetFormJson", "Learning")',
                    data: { id: id },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //alert(data);
                        $("#frmedit").formSerialize(data);
                        $("#NewsContent1").text(data.NewsContent);
                        $("#editDlg").modal();
                    }
                });
            }
        }

        function del(obj, id) {
            if (!!id) {
                $.deleteForm({
                    url: "/Learning/Delete",
                    param: { id: id },
                    success: function () {
                        $(obj).parents("tr").remove();
                    }
                });
            }
        }

        function query() {
            $('#queryDlg').modal();
        }

    </script>
}
